package com.sgb.merchant.widget;

import android.content.Context;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.link.entity.merchant.IndustryCategoryEntity;
import com.sgb.merchant.R;
import com.sgb.merchant.view.adapter.ItemTypeAdapter;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 王彬臣
 * @date: 2021/10/13
 * @Description: 类型弹框popowindow
 */
public class SelectTypeWindow extends BasePopWindow {
    ItemTypeAdapter mAdapter;


    public SelectTypeWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.merchant_popwindow_types;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        RecyclerView recyclerView = holder.getPop().findViewById(R.id.type_list);
        mAdapter=new ItemTypeAdapter(mContext,null);
        mAdapter.setItemSelect(true);
        mAdapter.setDefItem(0);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(mAdapter);
        mAdapter.setOnItemClick(new AdapterOnItemClick<IndustryCategoryEntity>() {
            @Override
            public void onItemClick(IndustryCategoryEntity entity, int position) {
                onResultClick.result(entity, position, null);
                dismiss();
            }
        });
        //设置背景
        setBgView(holder.getPop().findViewById(R.id.bg_pop_gray_layout));
    }

    /**
     * 设置数据
     * @param mList
     */
    public void  setData(List<IndustryCategoryEntity> mList){
        mAdapter.setDatas(mList);
    }

    /**
     * 设置数据和相关选择位置
     * @param mList
     * @param position
     */

    public void  setData(List<IndustryCategoryEntity> mList,int position){
        mAdapter.setDatas(mList);
        mAdapter.setDefItem(position);
    }
}
